const mongoose = require('mongoose')
const glob = require('glob')
const path = require('path')
// mongoose.set('useCreateIndex', true)
// 以zz用户访问
// (async function(){
//     await
// })()
exports.InitSchema = function () {
  // glob.sync会将匹配的路径放到一个数组里.
  glob.sync(path.join(__dirname, '/Schema', '**/*.js')).forEach(require)
}

exports.connect = async function connect () {
  mongoose.set('useCreateIndex', true)
  mongoose.connect('mongodb://localhost/mushstreet', { useNewUrlParser: true, useUnifiedTopology: true }).then(() => console.log('数据库连接成功')).catch(() => { console.log('数据库连接失败') })
}
